﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BLL;
using System.Web.UI.MobileControls;
using System.Data;

public partial class Module_ucMainNav : System.Web.UI.UserControl
{

    MenuBLL menuData = new MenuBLL();
    public string prefix_new = "bai-viet";
    public string prefix_product = "cua-hang";
    public string liClass = "";
    public string activeLink = "";
    public int totalProduct = 0;
    public decimal totalCost = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        activeLink = Request.Url.AbsolutePath;
        LoadCost();
        LoadCart();
    }

    protected void LoadCart()
    {
        List<ProductShop> listCart = new List<ProductShop>();
        listCart = ((MyShopCart)Session["shop"]).ListProduct;

        DataTable tb = Myfunction.ConvertToDataTable(listCart);
        rptListCart.DataSource = tb;
        rptListCart.DataBind();
    }

    private void LoadCost()
    {
        totalCost = ((MyShopCart)Session["shop"]).GetTotalCost();
        ltTotalCost.Text = String.Format("$ {0:0,0}", totalCost);
        Literal1.Text = String.Format("$ {0:0,0}", totalCost);

        totalProduct = ((MyShopCart)Session["shop"]).GetTotalProduct();
        ltTotalProduct.Text = totalProduct.ToString();
    }

    void LoadMenu()
    {

        var listMenu = menuData.GetByPositionAndLevel(1, 1);
    }
    protected void rptListCart_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex >= 0)
        {
            try
            {
                SizeBLL dataSize = new SizeBLL();
                ColourBLL dataColor = new ColourBLL();
                Literal ltSize = (Literal)e.Item.FindControl("ltSize");
                Literal ltColor = (Literal)e.Item.FindControl("ltColor");
                string nameSize = dataSize.GetById(int.Parse(ltSize.Text)).Name;
                string nameColor = dataColor.GetById(int.Parse(ltColor.Text)).Name;
                ltSize.Text = nameSize;
                ltColor.Text = nameColor;
            }
            catch { Exception ex; }
            
        }
    }
}